package zli.proxy.dynamicproxy.gpproxy.client;

import zli.proxy.dynamicproxy.gpproxy.proxy.GPClassLoader;
import zli.proxy.dynamicproxy.gpproxy.proxy.GPInvocationHandler;
import zli.proxy.dynamicproxy.gpproxy.proxy.GPProxy;

import java.lang.reflect.Method;

/**
 * @Desc
 * @Author Zerlinda
 * @Date 2022/5/13 14:26
 * @Version 1.0
 */
public class GPMeiPo implements GPInvocationHandler {
    private IPerson target;

    public IPerson getInstance(IPerson target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return (IPerson) GPProxy.newProxyInstance(new GPClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before: 我是地狱少女，已经收到你的需求开始物色对象");
        Object result = method.invoke(this.target, args);
        System.out.println("after: 开始交往");
        return result;
    }
}
